package com.auz.datagenerator.publishing.tcpip.client;

import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

public class StringClientPanel extends JPanel implements Runnable {

	private static final long serialVersionUID = 2032007041336165485L;
	private JTextArea writing;

	public StringClientPanel() {
		setLayout(new FlowLayout());

		writing = new JTextArea(12, 40);
		writing.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
		writing.setLineWrap(true);
		writing.setWrapStyleWord(true);
		writing.setAlignmentX(LEFT_ALIGNMENT);
		writing.setEditable(false);
		
		JScrollPane scrollPane = new JScrollPane(writing);
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
		add(scrollPane);
	}

	public void run() {
		setVisible(true);
	}

	/**
	 * Adds a value to the preview
	 * @param _value - the value to add to the preview
	 */
	public void addValue(String _text) {
		String toWrite = "\n".concat(_text);
		writing.append(toWrite);
		writing.setCaretPosition(writing.getCaretPosition()+toWrite.length());
	}

}
